<template>
	<view class="container">
		<header-bar :title=titleName>
			<uni-icons type="undo" size="23" slot="back"></uni-icons>
		</header-bar>
		<!-- 商品轮播图 -->
		<view class="carousel">
			<!--轮播图-->
			<swiper class="home-swiper" indicator-dots="true" :autoplay="autoplay" :interval="interval"
				:circular="circular" :duration="duration">
				<block v-for="(item,key) in lunboData" :key="key">
					<swiper-item class="swiper-item">
						<image :src="item.imgurl" class="slide-image" />
					</swiper-item>
				</block>
			</swiper>
		</view>
		<view class="introduce-section" :key="index" v-for="(goodsInf,index) in goodsInf">
			<text class="title">{{goodsInf.goodsTitle}}</text>
			<view class="price-box">
				<text class="price-tip">￥</text>
				<text class="price">{{goodsInf.goodsPirce}}</text>
				<text class="m-price">￥{{goodsInf.goodsMPrice}}</text>
				<text class="coupon-tip">{{goodsInf.goodsCoupon}}</text>
			</view>
			<view class="bot-row">
				<text>收藏量：{{goodsInf.goodsSales}}</text>
				<text>分享：{{goodsInf.goodsInventory}}</text>
				<text>浏览量：{{goodsInf.goodsBrowse}}</text>
			</view>
		</view>
		<!-- 分享 -->
		<view class="share-section" @click="shareShowMethod">
			<view class="share-icon">
				<text class="yticon icon-xingxing"></text>
				返
			</view>
			<text class="tit">该商品分享可领49减10红包</text>
			<text class="yticon icon-bangzhu1"></text>
			<view class="share-btn" @click="is_show_share_box = true">
				立即分享 >
				<text class="yticon icon-you"></text>
			</view>
		</view>
		<!-- 中间部分  -购买类型 -->
		<view class="c-list" @click="typeShowMethod">
			<van-cell is-link>
				<view slot="title">
					<view class="van-cell-text">购买类型</view>
					<view class="con">
						<text class="select-text" v-for="(sItem, sIndex) in specSelected"
							:key="sIndex">{{sItem.name}}</text>
					</view>
				</view>
			</van-cell>
		</view>
		<van-action-sheet @close="onClose" overlay close-on-click-overlay round :show="typeShow" :title="typeTitle">
			<!-- 类型信息 -->
			<view class="typeInformation">
				<view class="a-t">
					<image
						src="https://img11.360buyimg.com/n1/jfs/t1/135257/32/22355/280244/61e90204E52ca6244/a5bc31c99ad3401e.jpg.avif"
						role="img"></image>
					<view class="right" :key="index" v-for="(goodsInf,index) in goodsInf">
						<text class="price">￥{{goodsInf.goodsPirce}}</text>
						<text class="stock">库存：{{goodsInf.goodsInventory}}件</text>
						<view class="selected">
							已选：
							<text class="select-text" v-for="(sItem, sIndex) in specSelected"
								:key="sIndex">{{sItem.name}}</text>
						</view>
					</view>
				</view>
				<view v-for="(item,index) in specList" :key="index" class="attr-list">
					<text>{{item.name}}</text>
					<view class="item-list">
						<text v-for="(childItem, childIndex) in specChildList" v-if="childItem.pid === item.id"
							:key="childIndex" class="tit" :class="{selected: childItem.selected}"
							@click="selectSpec(childIndex, childItem.pid)">
							{{childItem.name}}
						</text>
					</view>
				</view>
				<view class="vButton">
					<van-button plain round block color="#fa436a" type="primary" @click="onClose"></van-button>
				</view>
			</view>
		</van-action-sheet>

		<!-- 中间部分 -促销活动 -->
		<view class="c-row b-b">
			<text class="tit">促销活动</text>
			<view class="con-list">
				<text>新人首单送20元无门槛代金券</text>
				<text>订单满300减20</text>
				<text>订单满500减50元</text>
				<text>单笔购买满两件免邮费</text>
			</view>
		</view>
		<!-- 中间部分 -服务 -->
		<view class="c-row b-b">
			<text class="tit">服务</text>
			<view class="bz-list con">
				<text>7天无理由退货 ·</text>
				<text>假一赔十 · </text>
			</view>
		</view>
		<uni-evaluate :list-data="listData" :rate="4" />
		<view class="page-bottom">
			<van-goods-action>
				<van-goods-action-icon icon="home-o" text="首页" link-type="switchTab" url="/pages/index/index" />
				<van-goods-action-icon icon="cart-o" text="购物车" link-type="switchTab" url="/pages/cart/index" />
				<van-goods-action-icon icon="shop-o" text="店铺" link-type="switchTab" url="/pages/shop/index" />
				<van-goods-action-button @click="addToShopCart" text="加入购物车" type="warning" />
				<van-goods-action-button @click="ImmediatePurchase" text="立即购买" />
			</van-goods-action>
		</view>
		<van-toast id="van-toast" />
		<uni-goods-nav :fill="true" :options="options" :button-group="customButtonGroup" @click="onClick"
			@buttonClick="buttonClick" />
			<echone-sku :show="popupShow" mode="forbidden" :theme-color="themeColor" :combinations="combinations"
				:specifications="specifications" :default-select-index="selectedIndex"
				:combinations-props="combinationsProps" :specifications-props="specificationsProps"
				@close="handleClose" @confirm="handleConfirm">
			</echone-sku>
		<shareColumn @share="share" :is_show_share_box="is_show_share_box"
			@hideColumn="is_show_share_box = !is_show_share_box"></shareColumn>
	</view>
</template>

<script>
	import uniEvaluate from '@/components/xiujun-evaluate/uni-evaluate.vue';
	import shareColumn from '@/components/share-column/share-column.vue'
	import {
			get_provider
		} from '@/components/utils/common.js'

	export default {
		components: {
			uniEvaluate,
			shareColumn
		},
		props: {
			nomsg: 'https://file.genepre.com/wechat/nomsg.png',
			orderInfo: {
				type: Object,
				default: {}
			},
			index: Number
		},
		data() {
			return {
				is_show_share_box: null,
				provider_list: [],
				titleName: "商品详情",
				popupShow: false,
				combinationsProps: {
					id: 'skuId',
					value: 'skuValue',
					image: 'skuImage',
					price: 'skuPrice',
					stock: 'skuStock'
				},
				themeColor: '#00D0D0',
				specificationsProps: {
					id: 'id',
					list: 'skuList',
					name: 'skuName'
				},
				combinations: [{
					skuId: '1',
					skuValue: '园艺工具-10件套',
					skuImage: 'https://img11.360buyimg.com/n1/jfs/t1/135257/32/22355/280244/61e90204E52ca6244/a5bc31c99ad3401e.jpg.avif',
					skuPrice: 89.0,
					skuStock: 10,
				}],
				specifications: [{
						skuName: '颜色分类',
						id: '123',
						skuList: ['草木绿','浅紫色', '天蓝色'],
					},
					{
						skuName: '款式',
						id: '456',
						skuList: ['普通款(5件套)',  '不锈钢款(5件套)', '印花款(5件套)','普通款(10件套)', '不锈钢款(10件套)','印花款(10件套)','地垫100*100cm'],
					}
				],
				selectedIndex: 0,
				options: [{
					icon: 'loop',
					text: '物物换'
				}, {
					icon: 'heart',
					text: '加入收藏',
				}, {
					icon: 'cart',
					text: '购物车',
					info: 2
				}],
				customButtonGroup: [{
						text: '线下交易',
						backgroundColor: 'linear-gradient(90deg, #1E83FF, #0053B8)',
						color: '#fff'
					},
					{
						text: '线上购买',
						backgroundColor: 'linear-gradient(90deg, #60F3FF, #088FEB)',
						color: '#fff'
					}
				],
				listData: [{
						header_img: "https://s2.loli.net/2022/05/26/rdRQtgNxYy8WFIw.jpg",
						user_name: "猫猫没有猫耳朵",
						rate: '5',
						create_time: "2022-5-20 16:30:22",
						content: "商品收到了，80.1元一套工具，质量不错，试了一下挺好用的，我很喜欢",
						imgs: ['https://img11.360buyimg.com/n1/jfs/t1/135257/32/22355/280244/61e90204E52ca6244/a5bc31c99ad3401e.jpg.avif',
							'https://img12.360buyimg.com/n7/jfs/t1/222844/31/1565/156060/61864a60E356b47af/8a05eaa7d08fdf92.jpg',
							'https://img14.360buyimg.com/n7/jfs/t1/206966/9/18618/104227/621ddd44E94f529bb/b6a68419b8a5b12c.jpg'
						]
					},
					{
						header_img: "https://s2.loli.net/2022/05/26/nxOlt3D6ofP4vgT.jpg",
						user_name: "鹿鹿迷路了i",
						rate: '5',
						create_time: "2022-5-20 16:30:22",
						content: "商品收到了，还是紫色的好看，质量挺好的，我很喜欢",
						imgs: ['https://img13.360buyimg.com/n7/jfs/t1/84121/24/18326/268966/62875ec6E64eddd55/2ef55d0738b75a2e.jpg',
							'https://img13.360buyimg.com/n7/jfs/t1/149660/31/6239/113504/5f41185dEd8cd7a96/553d6ca90a32e791.jpg'
						]
					}, {
						header_img: "https://s2.loli.net/2022/05/26/nxOlt3D6ofP4vgT.jpg",
						user_name: "鹿鹿迷路了i",
						rate: '5',
						create_time: "2022-5-20 16:30:22",
						content: "外观很漂亮，挺精致的，物流也很快，真心不错",
						imgs: ""
					}
				],
				//轮播图配置
				lunboData: [],
				autoplay: true, //是否自动切换
				interval: 3000, //自动切换时长
				duration: 1200, //滑动动画时长
				circular: true, //是否自动采用衔接滑动
				//商品信息
				goodsInf: [],
				//分享
				shareShow: false,
				shareTitle: '分享商品',
				shareInf: [],
				//类型
				typeShow: false,
				typeTitle: '商品类型',
				specSelected: [],
				specList: [{
						id: 1,
						name: '款式',
					},
					{
						id: 2,
						name: '颜色',
					},
				],
				specChildList: [{
						id: 1,
						pid: 1,
						name: '普通款',
					},
					{
						id: 2,
						pid: 1,
						name: '不锈钢款',
					},
					{
						id: 3,
						pid: 1,
						name: '印花款',
					},
					{
						id: 4,
						pid: 1,
						name: '地垫100*100cm',
					},
					{
						id: 5,
						pid: 2,
						name: '草木绿',
					},
					{
						id:6,
						pid: 2,
						name: '浅紫色',
					},
					{
						id: 7,
						pid: 2,
						name: '天蓝色',
					},
				],
			}
		},
		onLoad() {
			get_provider().then(res => {
				this.provider_list = res
			})
			//轮播图
			this.swiperPictures();
			//商品信息
			this.goodsInformation();
			//规格 默认选中第一条
			this.specList.forEach(item => {
				for (let cItem of this.specChildList) {
					if (cItem.pid === item.id) {
						this.$set(cItem, 'selected', true);
						this.specSelected.push(cItem);
						break; //forEach不能使用break
					}
				}
			});
		},
		methods: {
			//异步请求示例
			initData() {
				uni.request({
					url: 'http://xxx/sku/info',
					method: 'GET'
				}).then(res => {
					const result = res[1].data.data
					this.combinations = result.combinations
					this.specifications = result.specifications
					this.selectedSkuIdx = result.selectedSkuIdx
				})
			},
			handleClose() {
				this.popupShow = false
			},
			handleConfirm(obj) {
				this.popupShow = false
			},
			onClickItem(e) {
				if (this.current != e.currentIndex) {
					this.current = e.currentIndex;
				}
			},
			onClick(e) {
				uni.navigateTo({
					url: '/subpkg/shopping/shopping'
				})
			},
			buttonClick(e) {
				this.options[2].info++;
				this.popupShow = true;
			},
			//轮播图
			swiperPictures() {
				var data = {
					"datas": [{
							"id": 1,
							"imgurl": "https://img11.360buyimg.com/n7/jfs/t1/135257/32/22355/280244/61e90204E52ca6244/a5bc31c99ad3401e.jpg"
						},
						{
							"id": 2,
							"imgurl": "https://img12.360buyimg.com/n7/jfs/t1/222844/31/1565/156060/61864a60E356b47af/8a05eaa7d08fdf92.jpg"
						},
						{
							"id": 3,
							"imgurl": "https://img14.360buyimg.com/n7/jfs/t1/206966/9/18618/104227/621ddd44E94f529bb/b6a68419b8a5b12c.jpg"
						},
					]
				};
				this.lunboData = data.datas
			},
			//商品介绍
			goodsInformation() {
				var data = {
					"datas": [{
						"goodsId": '7',
						"goodsTitle": "尊福林 园艺工具套装家用种植工具箱种菜种花多肉松土铲子喷壶修枝剪刀组合园艺用品 园艺工具-10件套", //标题
						"goodsPirce": 80.1, //现价
						"goodsMPrice": 89.00, //原价
						"goodsCoupon": "9折", //折扣
						"goodsSales": 22,
						"goodsInventory": 8,
						"goodsBrowse": 320,
					}, ]
				};
				//把数值赋值给goodsInf商品信息介绍
				this.goodsInf = data.datas
			},
			//加载分享弹窗
			shareShowMethod() {
				this.shareShow = true
			},
			//关闭弹窗
			onClose() {
				this.shareShow = false;
				this.typeShow = false;
			},
			//分享去向
			shareTo(text) {
				console.log(text)
			},
			//加载类型弹窗
			typeShowMethod() {
				this.typeShow = true;
			},
			//选择规格
			selectSpec(index, pid) {
				let list = this.specChildList;
				list.forEach(item => {
					if (item.pid === pid) {
						this.$set(item, 'selected', false);
					}
				})

				this.$set(list[index], 'selected', true);
				//存储已选择
				/**
				 * 修复选择规格存储错误
				 * 将这几行代码替换即可
				 * 选择的规格存放在specSelected中
				 */
				this.specSelected = [];
				list.forEach(item => {
					if (item.selected === true) {
						this.specSelected.push(item);
					}
				})
			},
			//加入购物车
			addToShopCart() {
				console.log(this.goodsInf[0])
				var goodsinfo = {
					id: this.goodsInf[0].goodsId,
					title: this.goodsInf[0].goodsTitle,
					desc: this.goodsInf[0].goodsTitle,
					price: this.goodsInf[0].goodsPirce * 100,
					oprice: this.goodsInf[0].goodsMPrice * 100,
					num: 1,
					thumb: '/static/images/goodsimg/tu100.png'
				};
				// 
				this.$Toast({
					type: 'success',
					message: '添加成功',
					// duration: 0, // 持续展示 toast
				});
				//调用store 中 mutations来将商品加入到购物车
				this.$store.commit('addToCart', goodsinfo);
			},
			//立即购买
			ImmediatePurchase() {}
		}
	}
</script>

<style>
	.example-body {
		padding: 0;
		/* #ifndef APP-NVUE */
		display: block;
		/* #endif */
	}

	.goods-carts {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		position: fixed;
		left: 0;
		right: 0;
		/* #ifdef H5 */
		left: var(--window-left);
		right: var(--window-right);
		/* #endif */
		bottom: 0;
	}

	.container {
		width: 100%;
		height: 100%;
		margin: 0 auto;
	}

	.carousel {
		height: 722rpx;
		position: relative
	}

	/*轮播控件*/
	.home-swiper {
		width: 100%;
		height: 100%;
	}

	.swiper-item {
		display: flex;
		justify-content: center;
		align-content: center;
		height: 750upx;
		overflow: hidden;
	}

	.slide-image {
		width: 100%;
		height: 100%;
	}

	/* 商品介绍 */
	.introduce-section {
		background: #ffffff;
		padding: 20rpx 30rpx;
	}

	.introduce-section .title {
		font-size: 32rpx;
		color: #303133;
		height: 50rpx;
		line-height: 50rpx;
	}

	.introduce-section .price-box {
		display: flex;
		align-items: baseline;
		height: 50rpx;
		padding: 10rpx 0;
		font-size: 26rpx;
		color: #fa436a;
	}

	.introduce-section .price {
		font-size: 34rpx;
	}

	.introduce-section .m-price {
		margin: 0 12rpx;
		color: #909399;
		text-decoration: line-through;
	}

	.introduce-section .coupon-tip {
		align-items: center;
		padding: 4rpx 10rpx;
		background: #fa436a;
		font-size: 24rpx;
		color: #ffffff;
		border-radius: 6rpx;
		line-height: 1;
		transform: translateY(-4rpx);
	}

	.introduce-section .bot-row {
		display: flex;
		align-items: center;
		height: 30rpx;
		font-size: 24rpx;
		color: #909399;
	}

	.introduce-section .bot-row text {
		flex: 1;
	}

	.share-section {
		display: flex;
		align-items: center;
		color: #606266;
		background: linear-gradient(left, #fdf5f6, #fbebf6);
		padding: 12rpx 30rpx;
	}

	.share-section .share-icon {
		display: flex;
		align-items: center;
		width: 70upx;
		height: 30upx;
		line-height: 1;
		border: 1px solid #fa436a;
		border-radius: 4upx;
		position: relative;
		overflow: hidden;
		font-size: 22upx;
		color: #fa436a;

	}

	.share-section .share-icon:after {
		content: '';
		width: 50rpx;
		height: 50rpx;
		border-radius: 50%;
		left: -20rpx;
		top: -12rpx;
		position: absolute;
		background: #fa436a;
	}

	.share-section .icon-xingxing {
		position: relative;
		z-index: 1;
		font-size: 24rpx;
		margin-right: 35rpx;
		color: #fff;
		line-height: 1;

	}

	.share-section .tit {
		font-size: 28rpx;
		margin-left: 10rpx;
	}

	.share-section .icon-bangzhu1 {
		padding: 10rpx;
		font-size: 30rpx;
		line-height: 1;
	}

	.share-section .share-btn {
		flex: 1;
		text-align: right;
		font-size: 24rpx;
		color: #fa436a;
		background-color: transparent;
	}

	button {
		width: 10rpx;
		padding: 0 !important;
		border: none !important;
	}

	.share-section .icon-you {
		font-size: 24rpx;
		margin-left: 4rpx;
		color: #fa436a;
	}

	.shareInformation {
		width: 100%;
		height: 275px;
	}

	.c-list {
		padding: 0 20rpx;
		margin-top: 30rpx;
		width: 100%;
		font-size: 26rpx;
	}

	.c-list .van-cell-text {
		width: 25%;
		display: flex;
		float: left;
		color: #606266;
	}

	.c-list .con .select-text {
		margin-right: 10rpx;
		color: #303133;
	}

	.typeInformation {
		padding: 0 20rpx;
		width: 100%;
		margin-bottom: 5%;
	}

	.typeInformation .a-t {
		display: flex;
		width: 90%;
		margin: 25rpx 0 0 0;
	}

	.typeInformation .a-t image {
		width: 130rpx;
		height: 130rpx;
		border-radius: 8rpx;
	}

	.typeInformation .a-t .right {
		display: flex;
		flex-direction: column;
		padding-left: 24rpx;
		font-size: 26rpx;
		color: #606266;
		line-height: 42rpx;
	}

	.typeInformation .a-t .right .price {
		font-size: 32rpx;
		color: #fa436a;
		margin-bottom: 10rpx;

	}

	.typeInformation .a-t .right .select-text {
		margin-right: 10rpx;
	}

	.typeInformation .attr-list {
		display: flex;
		flex-direction: column;
		font-size: 30rpx;
		color: #606266;
		padding-top: 30rpx;
		padding-left: 10rpx;
	}

	.typeInformation .item-list {
		padding: 20rpx 0 0;
		display: flex;
		flex-wrap: wrap;
	}

	.typeInformation .item-list .selected {
		background: #fbebee;
		color: #fa436a;
	}

	.typeInformation .item-list text {
		display: flex;
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
		-webkit-box-pack: center;
		-webkit-justify-content: center;
		justify-content: center;
		background: #eee;
		margin-right: 20rpx;
		margin-bottom: 20rpx;
		border-radius: 100rpx;
		min-width: 60rpx;
		height: 60rpx;
		padding: 0 20rpx;
		font-size: 28rpx;
		color: #303133;
	}

	.typeInformation .vButton {
		width: 90%;
		margin: 0 auto;
		margin-top: 30rpx
	}

	.c-row {
		display: flex;
		align-items: center;
		padding: 20rpx 30rpx;
		position: relative;
		font-size: 26rpx;
		color: #606266;
		background-color: #FFFFFF;
	}

	.c-row .tit {
		width: 23%;
	}

	.c-row .con-list {
		flex: 1;
		display: flex;
		flex-direction: column;
		color: #303133;
		line-height: 40rpx;
	}

	.c-row .bz-list {
		height: 40rpx;
		font-size: 26rpx;
		color: #303133;
	}

	.c-row .con {
		flex: 1;
	}

	.c-row .bz-list text {
		display: inline-block;
		margin-right: 30rpx;
	}

	.eva-section {
		background-color: #FFFFFF;
		display: flex;
		flex-direction: column;
		margin-top: 16rpx;
	}

	.eva-section .eva-box {
		display: flex;
		padding: 20rpx 32rpx;
	}

	.eva-section .eva-box .myPhoto {
		flex-shrink: 0;
		width: 80rpx;
		height: 80rpx;
	}

	.eva-box .right {
		flex: 1;
		display: flex;
		flex-direction: column;
		font-size: 28rpx;
		color: #606266;
		padding-left: 26rpx;
	}

	.eva-box .right .con {
		font-size: 28rpx;
		color: #303133;
		padding: 20rpx 0;
	}

	.eva-box .right .bot {
		font-size: 24rpx;
		display: flex;
		color: #909399;
	}

	.detail-desc {
		background-color: #FFFFFF;
		margin: 16rpx 0px;
		height: 2026px;
	}

	.detail-desc .d-header {
		align-items: center;
		height: 80rpx;
		font-size: 30rpx;
		color: #303133;
		position: relative;
		text-align: center;
		line-height: 80rpx;

	}

	.detail-desc .d-header text {
		padding: 0 20rpx;
		background: #FFFFFF;
		position: relative;
	}

	.detail-desc .d-photo {
		width: 100%;
		height: 400px;
	}

	.page-bottom {
		position: fixed;
		left: 30rpx;
		bottom: 30rpx;
		display: flex;
		width: 690rpx;
		height: 100rpx;
		border-radius: 16rpx;

	}
</style>
